package kr.saeildamil.androidStudy_second.ani;

import java.util.ArrayList;

import kr.saeildamil.androidStudy_second.R;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;
import android.widget.ViewSwitcher.ViewFactory;

public class ViewSwitcherTest extends Activity {
	ImageSwitcher mSwitcher;
	int mAdIdx;
	ArrayList<Drawable> imgs;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_textswitchertest);

		imgs = new ArrayList<Drawable>();
		imgs.add(getResources().getDrawable(R.drawable.hyorin));
		imgs.add(getResources().getDrawable(R.drawable.ic_launcher));
		imgs.add(getResources().getDrawable(R.drawable.kimth));

		mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
		mSwitcher.setFactory(factory);
		mSwitcher.setImageDrawable(imgs.get(mAdIdx));
	}

	public void mOnClick(View v) {
		switch (v.getId()) {
		case R.id.btnnext:
			mAdIdx = mAdIdx == imgs.size() - 1 ? 0 : mAdIdx + 1;
			mSwitcher.setImageDrawable(imgs.get(mAdIdx));
			break;
		}
	}

	ViewSwitcher.ViewFactory factory = new ViewFactory() {
		public View makeView() {
			ImageView img = new ImageView(ViewSwitcherTest.this);
			return img;
		}
	};
}
